<template>
    <div
        class="CancelCard"
        v-loading="pageLoading"
        element-loading-background="rgba(255, 255, 255, 0.7)"
    >
        <el-card class="box-card">
            <div slot="headerss" class="clearfix text_fl">
                <span>销卡</span>
                <el-button class="btn_close" type="text" @click="handleClose">关闭</el-button>
            </div>
            <div class="CancelCard_body">
                <div v-show="!formDataInfo" class="CancelCard_form">
                    <el-form
                        ref="formData"
                        :model="formData"
                        :inline="true"
                        label-position="right"
                        size="small"
                        label-width="180px"
                        class="formData_form_inline"
                    >
                        <el-row class="el_row_item">
                            <el-col :span="11" :offset="1">
                                <el-form-item label="账户类别:" class="text_fl">
                                    <el-select
                                        v-model="formData.CATEGORY"
                                        placeholder="请选择账户类别"
                                        clearable
                                        @change="getCATEGORYObj"
                                        disabled
                                    >
                                        <el-option
                                            v-for="item in AccountionTYPE_INFO"
                                            :label="item.label"
                                            :value="item.code"
                                            :key="item.code"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11" :offset="1">
                                <el-form-item label="卡号:" class="text_fl">
                                    <el-select
                                        v-model.trim="formData.CARDNO"
                                        placeholder="请选择卡号"
                                        clearable
                                        disabled
                                        @change="getCARDNBRFun"
                                    >
                                        <el-option
                                            v-for="item in cardList_option"
                                            :label="item.CARDNBR"
                                            :value="item.CARDNBR"
                                            :key="item.CARDNBR"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row class="el_row_item">
                            <el-col :span="11" :offset="1">
                                <el-form-item label="卡产品:" class="text_fl">
                                    <span class="el-form-item-span">{{PRODUCT_value}}</span>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11" :offset="1">
                                <el-form-item label="是否存在卡片级分期计划:" class="text_fl">
                                    <span class="el-form-item-span">{{cardPhasedPlan?'是':'否'}}</span>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row class="el_row_item">
                            <el-col :span="11" :offset="1">
                                <el-form-item label="是否存在账户级分期计划:" class="text_fl">
                                    <span class="el-form-item-span">{{accountPhasedPlan?'是':'否'}}</span>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11" :offset="1">
                                <el-form-item label="电子现金余额:" class="text_fl">
                                    <span class="el-form-item-span">{{BALANCE_value}}</span>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row class="el_row_item">
                            <el-col :span="11" :offset="1">
                                <el-form-item label="是否绑定ETC:" class="text_fl">
                                    <span class="el-form-item-span"></span>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11" :offset="1">
                                <el-form-item label="是否存在待请款分期:" class="text_fl">
                                    <span
                                        v-if="result3046list.length>0"
                                        class="el-form-item-span"
                                        style="color:red;"
                                    >是</span>
                                    <span
                                        v-if="result3046list.length===0"
                                        class="el-form-item-span"
                                    >否</span>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <div class="text_center">
                            <el-button
                                type="primary"
                                size="small"
                                @click.native="handleClickSearch"
                            >自动分期计划查询</el-button>
                        </div>
                        <div class="cardY">
                            <div class="tab-header">
                                <div class="bodyTitlesLeft">销卡原因</div>
                            </div>
                            <el-row>
                                <el-checkbox-group
                                    name="closecodeList"
                                    v-model="formData.closecode"
                                    class="closecodeList_wrap"
                                >
                                    <template v-for="item in closecodeList">
                                        <el-checkbox
                                            :label="item.label"
                                            :key="item.code"
                                            @change="handelCheckboxClosecode($event,item.code)"
                                        ></el-checkbox>
                                    </template>
                                </el-checkbox-group>
                            </el-row>
                        </div>
                    </el-form>
                    <!-- 话术 -->
                    <div class="hstable_wrap" v-if="speechList.length!=0">
                        <el-table
                            :data="speechList"
                            border
                            stripe
                            header-row-class-name="headerRow"
                            ref="showListTable"
                            class="heard-bg business_table hstable"
                            @selection-change="handleSelectionChange"
                        >
                            <el-table-column type="selection" label=" " min-width="55"></el-table-column>
                            <el-table-column label="业务话术">
                                <template slot-scope="scope">{{scope.row.content}}</template>
                            </el-table-column>
                        </el-table>
                    </div>
                    <div class="text_center content_top">
                        <el-button
                            type="primary"
                            size="small"
                            icon="el-icon-circle-check"
                            @click="handerClickFormdata"
                        >提交</el-button>
                    </div>
                </div>
                <div v-if="formDataInfo">
                    <cancel-card-item :formDataInfo="formDataInfo"></cancel-card-item>
                </div>
                <el-dialog
                    v-drag
                    title="销卡提示信息"
                    :visible.sync="centerDialogVisible"
                    width="500px"
                    :append-to-body="true"
                    top="30vh"
                    :close-on-click-modal="false"
                    center
                >
                    <p>
                        卡号：
                        <span>{{this.formData.CARDNO}}</span>
                    </p>
                    <p>
                        账户类型：
                        <span>{{this.CATEGORY_filter}}</span>
                    </p>
                    <p class="text_center padding_top15">
                        <span style="color:#3a8ee6; ">您确认要销卡吗？</span>
                    </p>
                    <span slot="footer" class="dialog-footer">
                        <el-button
                            size="small"
                            icon="el-icon-circle-close"
                            @click="centerDialogVisible = false"
                        >取 消</el-button>
                        <el-button
                            type="primary"
                            size="small"
                            @click="handerCancelCard"
                            icon="el-icon-circle-check"
                            v-preventReClick
                        >确定</el-button>
                    </span>
                </el-dialog>
            </div>
        </el-card>
    </div>
</template>

<script>
import { mapGetters } from 'vuex';
import moment from 'moment';
import CancelCardItem from './childItem/CancelCardItem';
import {
    closePage,
    getDictMappingValue,
    itoStr,
    getDictSelectList,
    getDictSelectListOneValue,
    getCardInfo3004,
    updateDeal3004,
    updateDeal3601,
    getNewCardAccount3001,
    getNewFQFK3077,
    setICCardInfo,
    setETCCardInfo, getBusinessMenuId
} from '@/utils/Common';
// import { isEmptyObject, ChangePage, setNumber } from '@/utils/Object';

export default {
    name: 'CancelCard',
    data() {
        return {
            formData: {
                CATEGORY: '', // 账户类型
                isCATEGORY: '', // 显示的账户类型
                // CREDITLIMIT:'',//信用额度
                // AVLIMT:'',//可用额度
                // BALNCEFLG:'',//账户余额
                OPENDATE: '', // 开卡日期
                CARDSTAT: '', // 卡片状态
                CARDNO: '', // 卡号
                getCurrentDate: moment().format('YYYY-MM-DD'),
                getCurrentDateTime: moment().format('h:mm:ss'),
                CANCODE: 'T', // 挂失代码
                OPTION: '000000000000000',
                LOSTTYPE: 'PHN',
                closecode: [], // /销卡原因选项
                closecodeId: [],
            },
            closecodeList: [], // 销卡原因
            // acccodeList: [], // 挽留成功原因
            cancelCard: '1', // 销卡单选
            formDataInfo: '', // 销卡返回回来的数据
            // isCard3001:{},//3001信用卡账户查询
            centerDialogVisible: false,
            PRODUCT_value: '',
            pageLoading: true,
            DictClocdValue: '', // 字典查到的数据 //CLOCD 卡状态字段值 多个
            RTNIND_value: '', // 翻页标志
            BALANCE_value: '0',//取芯片卡可用余额 电子现金余额
            ETCSTATUS_value: false,//3134ETC签约关系查询交易接口
            CATEGORY_filter: '',//账户类型 lable
            cardList_option: '',//当前账户下的所有的卡
            newCardInfo_3004: '',//每次换卡的默认卡信息
            newCardAccountInfo_3001: '',//卡账户信息 每次切换账户更换信息
            newInstallmentInfo_3077: '',//3077数据 卡片级
            newAccountInstallmentInfo_3077: [],//3077数据 账户级
            accountPhasedPlan: false,//账户级
            cardPhasedPlan: false,//卡片级 账户还款
            result3014: {},
            result3077: {},
            result3046: {},
            result3077list: [],
            result3046list: [],
            speechList: [],//话术列表
            selectedList: [],

            NEXTDAY_3077: '20000101',//moment(new Date(new Date().getTime() - (1000 * 60 * 60 * 24 * 365))).format('YYYYMMDD'),//翻页交易日期
            NEXTMPNO_3077: '',//翻页分期付款序号
            RtnindFlag: '',//翻页标志
            startDate: '20000101', // 开始日期
            endDate: moment(new Date()).format('YYYYMMDD'), // 结束日期 默认为当前日期
            precardstat: '',//挂失前状态
            MenuId: '',
            productId: '',
        };
    },
    components: { CancelCardItem },
    computed: {
        ...mapGetters([
            'defaultParams',
            'cardInfo_3004',
            'cardAccountInfo_3001',
            'AccountionTYPE_INFO',
            'cardList_3601', //
            'pinFlag',
            'currentSessionObj',
            'InstallmentInfo_3077',
            'isCurrentMenuInfo',
            'businessMenu',
            'checAllData',
        ]),
    },
    filters: {
        isDateVal: (value) => {
            value = (`${value}`).trim();
            if (value) {
                return moment(value, 'YYYYMMDD').format('YYYY-MM-DD');
            }
            return '';
        },
        isTimeVal: (value) => {
            value = (`${value}`).trim();
            value = value.substring(0, 6);
            if (value) {
                return moment(value, 'hhmmss').format('HH:mm:ss');
            }
            return '';
        },
        filterExpire: (value) => {
            value = (`${value}`).trim();
            if (value) {
                return moment(value, 'YYMM').format('YY-MM');
            }
            return '';
        },
        filterCANCLCODE: (value, DictClocdValue) => {
            value = (`${value}`).trim();
            if (value === '') return '正常';
            for (let index = 0; index < DictClocdValue.length; index++) {
                const element = DictClocdValue[index];
                if (element.code === value) {
                    return element.label;
                }
            }
        },
    },

    async mounted() {
        this.MenuId = this.$route.params.id || '';
        await this.setDefaultCardInfo();
        await this.getExecuteFun();
        // 进线时 把 newCardInfo_3004 的数据赋值 后面都是从 newCardInfo_3004 里取
        // 修改默认卡
        // 跟默认卡相关的字典
        this.getDictOption();
        //  查字典 option
        this.getconfigDict();
        //this.judgePlanFun();
        await this.get3014();

        if (this.cardInfo_3004.MAFLAG + '' === '1') {
            if (this.cardList_3601.length == 1) {
                // 一张卡
                this.$alert(
                    "当前用户名下只有一张卡,请直接进入销户页面操作！",
                    '销卡提示',
                    { customClass: 'warning', type: 'warning', showClose: false },
                ).then(() => {
                    closePage(this.$route, this, 1);
                });
            } else {
                let ifneedflag = false;
                for (let i = 0; i < this.cardList_3601.length; i++) {
                    if (this.cardList_3601[i].CARDNBR !== this.cardInfo_3004.CARDNO) {
                        if (this.cardList_3601[i].CARDSTAT.trim() !== 'T' && this.cardList_3601[i].CARDSTAT.trim() !== 'Q') {
                            console.log("卡状态：" + this.cardList_3601[i].CARDSTAT.trim());
                            ifneedflag = false;
                            break;
                        } else {
                            ifneedflag = true;
                        }
                    }
                }

                if (ifneedflag) {
                    this.$alert(
                        "名下只有一张卡未注销，需要进行销户！",
                        '销卡提示',
                        { customClass: 'warning', type: 'warning', showClose: false },
                    ).then(() => {
                        //closePage(this.$route, this, 1);
                        return;
                    });
                }

                if (this.cardPhasedPlan || this.accountPhasedPlan) {
                    //该卡为自动分期卡，请出具工单办理
                    this.$alert(
                        '该卡名下存在卡片/账户级分期计划，请确认是否需要取消分期计划或降额？',
                        '提示',
                        { customClass: 'warning', type: 'warning', showClose: false },
                    ).then(() => {

                    });
                }
            }

        }
        // 3096IC卡交易明细查询
        await setICCardInfo(this.formData.CARDNO, this);
        // 3134ETC签约关系查询交易接口
        // await setETCCardInfo(this.formData.CARDNO, this);
        await this.getspeechList();
        this.pageLoading = false;
    },
    methods: {
        // 修改默认卡
        async setDefaultCardInfo() {
            if (!this.newCardInfo_3004) {
                this.newCardInfo_3004 = JSON.parse(JSON.stringify(this.cardInfo_3004));
            };
            if (!this.newCardAccountInfo_3001) {
                this.newCardAccountInfo_3001 = JSON.parse(JSON.stringify(this.cardAccountInfo_3001));
            };
            if (!this.newInstallmentInfo_3077) {
                this.newInstallmentInfo_3077 = JSON.parse(JSON.stringify(this.InstallmentInfo_3077));
            };
            this.getNew3004();
            //await getNewFQFK3077('', this, '2', this.newCardAccountInfo_3001.CUSTID, this.newCardAccountInfo_3001.KEYTYPE, this.newCardAccountInfo_3001.CATE);
            await this.get3077();
            await this.get3046();
        },
        getNew3004() {
            this.formData.OPENDATE = this.newCardInfo_3004.OPENDATE || '';// 开卡日期
            this.formData.CARDSTAT = this.newCardInfo_3004.CARDSTAT || '';// 卡片状态
            this.precardstat = this.newCardInfo_3004.CARDSTAT.trim() === '' ? '空' : this.newCardInfo_3004.CARDSTAT.trim();
            this.formData.CARDNO = this.newCardInfo_3004.CARDNO || '';// 卡号
            this.formData.CATEGORY = this.newCardInfo_3004.CATEGORY + '' || '';//账户类别
            // this.productId = itoStr(this.newCardInfo_3004.PRODUCT, 4);
            // if (this.productId === '0090') {
            //     //该卡为自动分期卡，请出具工单办理
            //     this.$alert(
            //         '该卡为自动分期卡，请出具工单办理！',
            //         '提示',
            //         { customClass: 'warning', type: 'warning', showClose: false },
            //     ).then(() => {

            //     });
            // }
        },
        //根据菜单id查询话术列表
        async getspeechList() {
            console.log("this.isCurrentMenuInfo.id", this.isCurrentMenuInfo.id);
            var checkParam = {
                'id': this.MenuId || this.isCurrentMenuInfo.id,
            };
            this.$post.busiMenu.getlistByMenuId(checkParam).then((res) => {
                console.log("话术查询结果：", res);
                if (res.status === 200) { // http通讯成功
                    if (res.data.status == 0) { // 业务请求成功
                        this.speechList = res.data.content;
                    }
                }
            });
        },
        handleSelectionChange(val) {
            this.selectedList = val;
        },

        //页面进入限制条件
        getExecuteFun() {
            let condition1 = '';


            // 商务卡账户
            if (this.formData.CATEGORY === '20') {
                this.$alert(
                    `当前用户为：${this.CATEGORY_filter}，不支持销卡操作！`,
                    '销卡提示',
                    { customClass: 'warning', type: 'warning', showClose: false },
                ).then(() => {
                    closePage(this.$route, this, 1);
                });
            };
            // 存在分期

            if (this.result3077.sysHead.rspCd === '000000' && this.result3077list.length > 0) {

                for (let i = 0; i < this.result3077list.length; i++) {
                    if (this.formData.CARDNO.trim() === this.result3077list[i].CARDNBR.trim()) {
                        this.$alert(
                            `存在分期，不支持销卡操作！`,
                            '销卡提示',
                            { customClass: 'warning', type: 'warning', showClose: false },
                        ).then(() => {
                            closePage(this.$route, this, 1);
                        });
                        break;
                    }
                }
            }
            // 存在分期

            // if (this.result3046.sysHead.rspCd === '000000' && this.result3046list.length > 0) {

            //     this.$alert(
            //         `存在分期，不支持销卡操作！`,
            //         '销卡提示',
            //         { customClass: 'warning', type: 'warning', showClose: false },
            //     ).then(() => {
            //         closePage(this.$route, this, 1);
            //     });

            // }


        },
        //  查字典
        async getconfigDict() {
            // XH_REASON
            this.DictClocdValue = await getDictSelectList('CLOCD', this);
            // this.CATEGORY_option = await getDictSelectList('CATE', this);

            // 获取 销卡原因 选项 
            this.closecodeList = await this.getDictDetails('XH_REASON');
            this.getCardListOption(this.formData.CATEGORY);

        },
        // 跟默认卡相关的字典
        async getDictOption() {
            this.CATEGORY_filter = await getDictMappingValue('CATE', this.newCardInfo_3004.CATEGORY, this);
            this.PRODUCT_value = await getDictMappingValue('PRODUCT', this.newCardInfo_3004.PRODUCT, this);
        },
        ////////////////////////////////////////////////////////////////
        // 获取账户类型
        getCATEGORYObj(val) {
            console.log('val', val);
            // 获取账户类型
            this.AccountionTYPE_INFO.some(async (item) => {
                if (item.code === val) {
                    this.CATEGORY_filter = item.label;
                    // 更新 newCardAccountInfo_3001
                    await getNewCardAccount3001(item.CARDNBR, this);
                    // 跑账户级的3077
                    //await getNewFQFK3077('', this, '2', this.newCardAccountInfo_3001.CUSTID, this.newCardAccountInfo_3001.KEYTYPE, this.newCardAccountInfo_3001.CATE);


                    return true
                }
            });
            console.log('this.CATEGORY_filter', this.CATEGORY_filter);
            //获取当前账户类型下 所有的卡 
            this.getCardListOption(val);

        },
        // 选择 选中的需要操作的卡 后
        async getCARDNBRFun(cardNo) {
            this.pageLoading = true;
            // 选中 需要操作的卡后 需要重新跑 3004接口
            console.log("cardNo", cardNo);
            this.formData.CARDNO = cardNo;
            // 更新 newCardInfo_3004 里的值
            await getCardInfo3004(cardNo, this);
            this.getNew3004();
            // 页面进入校验 规则
            this.getExecuteFun();
            // 再更新一下字典值
            await this.getDictOption();
            // this.setTableDataValue();
            // 3077 卡片级的数据
            //await getNewFQFK3077(this.formData.CARDNO, this);
            await this.get3014();
            //this.judgePlanFun();

            await this.get3077();
            await this.get3046();


            // 每换一次卡 就跑一次交易
            // 3096IC卡交易明细查询
            await setICCardInfo(this.formData.CARDNO, this);
            // 3134ETC签约关系查询交易接口
            //await setETCCardInfo(this.formData.CARDNO, this);
            this.pageLoading = false;
        },
        async get3014() {
            const appBody = {
                CARDNBR: this.formData.CARDNO, // 证件号码
                PINFLAG: '0', //验密标识
                PIN: '',// 密码
            };
            const defaultParams = JSON.parse(JSON.stringify(this.defaultParams));
            defaultParams.body.appHead.tranCode = '3014';
            defaultParams.body.appBody = appBody;
            // 3077交易

            await this.$post.common.transPort(defaultParams).then((res) => {
                if (res.status === 200) {
                    let result = JSON.parse(res.data.jsonRes);
                    console.log("result3014:", result);
                    if (result.sysHead.rspCd === '000000') {

                        //判断是否存在卡片级自动分期
                        if (result.body.appBody.CPNO + '' != '0') {
                            this.cardPhasedPlan = true;
                        }
                        if (result.body.appBody.CPNOACCT + '' != '0') {
                            this.accountPhasedPlan = true;
                        }
                    }
                }
            });
        },
        async get3046() {
            const appBody_3046 = {
                OPT: 1, // 查询方式 1-用卡号查询 2-用证件号码查询
                CARDNBR: this.formData.CARDNO, // 卡号
                MPTYPE: '', // 分期类型,y-账单分期
                STATUS: '30', // 分期申请状态,30-待请款
                PINFLAG: '0', // 是否检查密码标志 0-不检查
                RTNIND: '', // 翻页标志 首次传空， 翻页传1
                APPREF: '', // 分期申请编号，首次查询时送空， 下翻页查询时上送上次查询结果的最后一条记录返回的分期付款申请编号
            };
            const defaultParams_3046 = JSON.parse(JSON.stringify(this.defaultParams));
            defaultParams_3046.body.appHead.tranCode = '3046';
            defaultParams_3046.body.appBody = appBody_3046;
            await this.$post.common.transPort(defaultParams_3046).then((res) => {
                if (res.status === 200) {
                    this.result3046 = JSON.parse(res.data.jsonRes);
                    if (this.result3046.sysHead.rspCd === '000000' && this.result3046.body.appBody.dataList.length > 0) {
                        this.result3046list = this.result3046.body.appBody.dataList;
                    }

                    console.log("this.result3046:", this.result3046);
                }
            });
        },

        async get3077() {

            const appBody = {
                CARDNBR: this.formData.CARDNO, // 卡号
                MPTYPE: '',
                OPERCODE: '1',
                OPT: '1',
                PINFLAG: '0', //验密标识
                PIN: '',// 密码
                BEGDAY: this.startDate, // 起始日期
                ENDDAY: this.endDate, // 结束日期 
                RTNIND: this.RtnindFlag,// 翻页标志 首次传空， 翻页传1
                NEXTDAY: this.NEXTDAY_3077,// 首次查询时送查询起始日期， 下翻页查询时上送上次查询结果的最后一条记录返回的分期付款交易日期
                NEXTMPNO: this.NEXTMPNO_3077,// 首次查询时送起始序号，默认为0 下翻页查询时上送上次查询结果的最后一条记录返回的交易序号
            };

            const defaultParams = JSON.parse(JSON.stringify(this.defaultParams));
            defaultParams.body.appHead.tranCode = '3077';
            defaultParams.body.appBody = appBody;
            // 3077交易
            //console.log("this.appBody3077***********", appBody);
            await this.$post.common.transPort(defaultParams).then(async (res) => {
                if (res.status === 200) {
                    const result = JSON.parse(res.data.jsonRes);
                    this.result3077 = result;
                    if (result.sysHead.rspCd === '000000') {
                        //console.log("this.result3077***********", result);
                        this.result3077list.push(...result.body.appBody.dataList);
                        this.NEXTDAY_3077 = result.body.appBody.dataList[result.body.appBody.dataList.length - 1].BEGYM;
                        this.NEXTMPNO_3077 = result.body.appBody.dataList[result.body.appBody.dataList.length - 1].MPNO;
                        // 修改翻页标志 
                        this.RtnindFlag = result.body.appBody.RTNIND;
                        if (result.body.appBody.RTNIND === '1') {
                            await this.get3077();
                            // console.log("this.mpappnum", this.mpappnum);
                        }
                    }
                }
            });
        },


        //获取当前账户类型下 所有的卡 
        getCardListOption(CATEGORY_val) {
            this.cardList_option = this.cardList_3601.filter((item) => (item.CATEGORY + '').trim() === CATEGORY_val);
            console.log(" this.cardList_option ", this.cardList_option);
            if (this.cardInfo_3004.CATEGORY + '' === CATEGORY_val) {
                this.formData.CARDNO = this.cardInfo_3004.CARDNO;  // 卡号
                console.log('this.formData.CARDNO', this.formData.CARDNO);
            } else {
                this.formData.CARDNO = '';
            }
        },
        ///////////////////////////////////////////////////////////////
        // 查字典 特殊字段
        // async getDictSpecialValue(taget) {
        //     const params = {
        //         cfgNo: taget,
        //         bankNum: this.defaultParams.body.appHead.bnknbr,
        //         sect: '0000',
        //     };
        //     let value;
        //     await this.$post.dictDetail.queryConfig(params).then((res) => {
        //         // console.log(res,'9031')
        //         if (res.status === 200) {
        //             value = res.data.content.cfgEdit;
        //         }
        //     });
        //     return value;
        // },
        // 查字典
        async getDictDetails(val) {
            let params = {};
            let accountName;
            params = {
                dictValue: val,
                pageNum: 1,
                pageSize: 1000,
            };
            await this.$post.common.getBaseDataList(params).then((res) => {
                console.log(res, 'res');
                if (res.status === 200) {
                    accountName = res.data.content;
                } else {
                    this.$message.error(res.data.msg);
                }
            });
            return accountName;
        },

        // isfilterDateVal(value) {
        //     value = (`${value}`).trim();
        //     if (value === '0') return ''
        //     if (value) {
        //         return moment(value, 'YYYYMMDD').format('YYYY-MM-DD');
        //     }
        //     return '';
        // },
        // BALANCE_value

        // 销卡原因
        handelCheckboxClosecode(event, code) {
            if (event) {
                this.formData.closecodeId.push(code);
            } else {
                this.formData.closecodeId.forEach((item, i) => {
                    if (item === code) {
                        this.formData.closecodeId.splice(i, 1);
                    }
                });
            }
        },
        // 客户销卡动作 挽留 和销卡 这两个有一个是必填项 这个两个必填项 会带出另一个必填项
        //             detention:'',//挽留单选
        // cancelCard:'',//销卡单选
        async handerClickFormdata() {
            // 该卡为未制卡不能做此操作
            if (this.formData.CARDSTAT === 'A') {
                if (((this.formData.OPENDATE + '').trim()) == '00000000') {
                    this.$alert('该卡为未制卡不能做此操作！', '销卡提示', {
                        customClass: 'warning', type: 'warning',
                    });
                    return false;
                }
            }
            //this.getExecuteFun();
            let msg = '';
            let value = this.BALANCE_value * 1;
            if (value > 0) {
                msg = '该账户存在电子现金余额，';
            }
            // if (this.formData.ETCSTATUS_value) {
            //     msg = msg + '存在ETC，';
            // }

            if (this.accountPhasedPlan) {
                msg = msg + '存在账户级分期计划，';
            }
            if (this.result3046list.length > 0) {
                msg = msg + '存在待请款分期，';
            }
            let closecodestr = '';	// 销卡原因代码串  closecode
            let ccdescstr = ''; // 销卡原因描述串
            // 表示选择了挽留客户选项，则需要继续判断是否选择了挽留客户原因
            const closecodeVal = this.formData.closecode;
            const closecodeIdVal = this.formData.closecodeId;
            console.log('closecodeIdVal', closecodeIdVal);
            console.log('closecodeVal', closecodeVal);
            for (let n = 0; n < closecodeVal.length; n++) {
                closecodestr = closecodestr + closecodeIdVal[n] + ',';
                ccdescstr = `${ccdescstr + closecodeVal[n]}<br>`;
            }

            console.log('closecodestr 销卡原因代码串', closecodestr);
            console.log('ccdescstr 销卡原因描述串', ccdescstr);
            // 选项原因 入库
            if (closecodeIdVal.length > 0) {
                await this.addTbCloseCard(closecodestr, ccdescstr);
            } else {
                this.$alert('请选择一项销卡原因', '销卡提示', {
                    customClass: 'warning', type: 'warning',
                });
                return false;
            }


            console.log("this.selectedList.length", this.selectedList.length);
            if (this.selectedList.length != this.speechList.length) {
                this.$alert('话术尚未全部勾选！', '提示', {
                    customClass: 'warning', type: 'warning',
                });
                return;
            }
            if (msg !== '') {
                this.$confirm(msg + '是否确认销卡？', '销卡提示',
                    {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        // customClass: 'warning', type: 'warning',
                        showClose: false
                    },
                ).then(async () => {

                    // 员工卡 给提示框 PRODUCT
                    if ((this.newCardInfo_3004.PRODUCT + '') === '35' || (this.newCardInfo_3004.PRODUCT + '') === '64') {
                        this.$confirm(`当前卡片为${this.PRODUCT_value},员工是否离职？`, '销卡提示', {
                            confirmButtonText: '离职',
                            cancelButtonText: '非离职',
                            type: 'warning',
                            showClose: false,
                        }).then(() => {
                            // CREDITLIMIT 永久信用额度  BALNCE 账面余额
                            // 账面余额＞0或信用额度＞50000禁止销卡
                            if ((this.newCardAccountInfo_3001.BALNCE > 0 && this.newCardAccountInfo_3001.BALNCEFLG === '+') || this.newCardAccountInfo_3001.CREDITLIMIT > 50000) {
                                this.$alert(
                                    '禁止销卡，账面余额或信用额度不满足销卡条件',
                                    '销卡提示',
                                    { customClass: 'warning', type: 'warning', showClose: false },
                                ).then(() => {
                                    closePage(this.$route, this, 1);
                                });
                            } else {
                                this.centerDialogVisible = true;
                            }
                        }, () => { // 需要校验卡号是否为空 为空提示
                            this.centerDialogVisible = true;
                        })
                    } else {
                        this.centerDialogVisible = true;
                    }
                });
            } else {
                // 员工卡 给提示框 PRODUCT
                if ((this.newCardInfo_3004.PRODUCT + '') === '35' || (this.newCardInfo_3004.PRODUCT + '') === '64') {
                    this.$confirm(`当前卡片为${this.PRODUCT_value},员工是否离职？`, '销卡提示', {
                        confirmButtonText: '离职',
                        cancelButtonText: '非离职',
                        type: 'warning',
                        showClose: false,
                    }).then(() => {
                        // CREDITLIMIT 永久信用额度  BALNCE 账面余额
                        // 账面余额＞0或信用额度＞50000禁止销卡
                        if ((this.newCardAccountInfo_3001.BALNCE > 0 && this.newCardAccountInfo_3001.BALNCEFLG === '+') || this.newCardAccountInfo_3001.CREDITLIMIT > 50000) {
                            this.$alert(
                                '禁止销卡，账面余额或信用额度不满足销卡条件！',
                                '销卡提示',
                                { customClass: 'warning', type: 'warning', showClose: false },
                            ).then(() => {
                                closePage(this.$route, this, 1);
                            });
                        } else {
                            this.centerDialogVisible = true;
                        }
                    }, () => { // 需要校验卡号是否为空 为空提示
                        this.centerDialogVisible = true;
                    })
                } else {
                    this.centerDialogVisible = true;
                }
            }
        },

        // 提交做4018交易
        async addTbCloseCard(closecodestr, ccdescstr) {
            let callNum = '';
            // if (this.currentSessionObj.direction === 'Out') { // 外呼
            //     callNum = this.currentSessionObj.ani;
            // } else if (this.currentSessionObj.direction === 'In') { // 外拨
            //     callNum = this.currentSessionObj.dnis;
            // }

            const paramsVal = {
                busiType: '2',//业务类型，1-销户，2-销卡
                acccode: '', // 挽留多选的选项值id
                wlFlag: '0',//挽留成功
                // xhFlag: '0',//是否可销户标志
                wlReason: '', // 挽留原因
                // bankNum: this.defaultParams.body.appHead.bnknbr,
                // callNo: callNum, // 客户号码
                createUser: '',//
                // cardcount: '', // 给空
                // cardproduct: this.cardInfo_3004.PRODUCT, // 产品编号
                // cardstate: this.cardInfo_3004.CARDSTAT, // O
                closeReason: ccdescstr, // 销卡原因
                // closeBy: this.defaultParams.body.appHead.opeNo, // //操作员号 取用户信息agNum字段
                // closeDt: moment().format('YYYYMMDD'),//日期时间
                cardNo: this.formData.CARDNO, // 卡号
                // closeTm:moment().format('hh:mm:ss'),//time 小时
                closecode: closecodestr, // 销卡原因多选id
                // gender: 'M', // 性别
                // idNo: this.cardInfo_3004.CUSTID, // 证件号
                // idType: this.cardInfo_3004.KEYTYPE, // 证件类型
                optflag: '1', // 0和1 用来判断是销卡还是挽留  0挽留,1销卡
                updateTime: moment().format('YYYYMMDD')
            };
            await this.$post.queryServiceClass.cancelCardCause(paramsVal).then((res) => {
                console.log(res, 'addTbCloseCard');
                if (res.status === 200) { // 请求成功
                    const cardlossofs = res.data;
                } else {
                    this.$alert('请求失败！', '提示', {
                        customClass: 'error', type: 'error',
                    });
                }
            });
        },
        // 提交做4018交易 销卡交易
        async handerCancelCard() {
            const defaultParam = JSON.parse(JSON.stringify(this.defaultParams));
            defaultParam.body.appHead.tranCode = '4018';// 修改交易号
            defaultParam.body.appBody = {
                PINFLAG: this.pinFlag,
                PIN: '',
                CARDNO: this.formData.CARDNO, // 卡号
                CARDNBR: this.formData.CARDNO, // 卡号
                CANCODE: this.formData.CANCODE,// 挂失代码
                LOSTTYPE: this.formData.LOSTTYPE,// LOSTTYPE 挂失方式  LTR信函挂失 PHN电话挂失  VTB到分行挂失 VTC到信用卡中心挂失
                OPTION: this.formData.OPTION,
            }
            await this.$post.common.transPort(defaultParam).then((res) => {
                if (res.status === 200) { // 请求成功
                    const cardlossofs = JSON.parse(res.data.jsonRes);
                    console.log(cardlossofs, '4018_卡资料信息');
                    if (cardlossofs.sysHead.rspCd == '000000') { // 交易成功
                        this.formDataInfo = cardlossofs.body.appBody;
                        if (this.formData.CARDNO === this.cardInfo_3004.CARDNO) {
                            updateDeal3004(this.cardInfo_3004.CARDNO, this);
                            this.updateCheckData(this.precardstat, cardlossofs.body.appBody.STS);
                        }
                        updateDeal3601(this.newCardInfo_3004.CARDNO, this.newCardInfo_3004.KEYTYPE, this.newCardInfo_3004.CUSTID, this);

                        this.formDataInfo.getCurrentDateTime = this.formData.getCurrentDateTime;
                    } else {
                        const ErrorMessage = `错误码：${cardlossofs.sysHead.rspCd} ` + `错误信息：${cardlossofs.sysHead.rspMsg}`;
                        this.$alert(ErrorMessage, cardlossofs.sysHead.busiName, '提示', {
                            customClass: 'error', type: 'error',
                        });
                    }
                    this.centerDialogVisible = false;// 关闭 提示框

                }
            });
        },

        updateCheckData(precardstat, nowcardstat) {
            const checAllDataItem = JSON.parse(JSON.stringify(this.checAllData));
            precardstat = precardstat.trim() === '' ? '空' : precardstat.trim();
            nowcardstat = nowcardstat.trim() === '' ? '空' : nowcardstat.trim();
            checAllDataItem[precardstat].falg = false;
            checAllDataItem[nowcardstat].falg = true;
            // 修改验证开关 结束后再 保存一下 checAllDataItem
            // console.log(`这里是修改了 预留手机号状态：名称为：${checAllDataItem[precardstat].label}值为：${checAllDataItem[precardstat].falg}：大对象为：${checAllDataItem}`);
            this.$store.commit('common/SAVE_CHECK_DATA', checAllDataItem);
        },

        //
        handleClickSearch() {
            this.MenuId = getBusinessMenuId('/instalment/automaticstagset', this.businessMenu);
            console.log('this.MenuId____', this.MenuId);
            this.$router.push({ name: 'automaticstagset', path: '/instalment/automaticstagset', params: { id: this.MenuId } });
        },

        // 点击关闭
        handleClose() {
            closePage(this.$route, this, 1);
        },

    },
};
</script>

<style lang='scss' >
.CancelCard {
    .cardY {
        width: 98%;
        margin: 10px auto 0;
        padding: 8px 30px 20px 30px;
        border-radius: 5px;
        border: 1px solid #ccc;
    }
    .footer {
        margin: 10px 0 10px 0;
    }
    .labelWidth {
        label {
            width: 100px !important;
        }
        div {
            margin-left: 100px !important;
        }
    }
    .CancelCard_body {
        padding-bottom: 30px;
        .closecodeList_wrap {
            .el-checkbox {
                .el-checkbox__input {
                }
                .el-checkbox__label {
                    width: 180px;
                }
            }
        }
    }
    .el-checkbox {
        margin: 8px 0;
        .el-checkbox__label {
            font-size: 14px;
            /* color: #606266; */
            // font-weight: 700;
        }
    }
    .text_center {
        text-align: center;
    }

    .btn_item {
        float: left;
        width: 100%;
        margin: 20px 0;
    }

    .el-card__header {
        padding: 8px !important;
    }
    .backgroundRow {
        margin-top: 20px;
        padding: 10px 5px;
        background-color: #ecf5ff;
    }
    .el-form-item__content {
        line-height: 0;
    }
    .el-card.is-always-shadow {
        -webkit-box-shadow: none;
        box-shadow: none;
    }
    .el-card {
        border: none;
    }
    .tab-header {
        text-align: center;
    }
}
</style>
